from  scipy.stats import chi2_contingency
import numpy as np
kf_data = np.array([[11.7,8.7,15.4,8.4], [18.1,11.7,24.3,13.6],
              [26.9,20.3,37,19.3],[41,30.9,54.6,35.1],
              [66,54.3,71.1,50]])
kf = chi2_contingency(kf_data)
print('chisq-statistic=%.4f, p-value=%.4f, df=%i expected_frep=%s' %kf)

# chisq-statistic=2.9208, p-value=0.9961, df=12 expected_frep=[[11.70042044  8.998674   14.46649418  9.03441138][17.92123221 13.78303687 22.15795602 13.8377749 ][27.39804334 21.07155563 33.87516171 21.15523933][42.77800776 32.90012937 52.89107374 33.03078913][63.90229625 49.14660414 79.00931436 49.34178525]]
#  因为p值=0.9961>0.05, 故接受原假设, 认为死亡年龄和居住地、性别无显著差别。
